package com.eascs.workflow.processAuthorization.dao.impl;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.web.sso.User;
import com.eascs.workflow.common.dao.BaseDao;
import com.eascs.workflow.processAuthorization.entity.ProcessAuth;
import com.eascs.workflow.processAuthorization.vo.ProcessAuthorizationVo;

@Repository
public class ProcessAuthorizationDao  extends BaseDao {
	
	public PageResult<Object[]> findProcessAuthorizationInfo(ProcessAuthorizationVo vo) {
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, vo.getPageSize(), vo.getShowPage());
		StringBuilder sql = new StringBuilder();
		sql.append("select p.id,wt.`name`,wf.name  name2,p.roll_outer_name,p.roll_iner_name,p.auth_bigin_date,p.auth_end_date,case when (p.auth_status='Y') then '有效' else '无效' end as auth_status  from process_auth p left join wf_dictionary_data wt on  wt.type='11' and wt.`code`= p.process_main_code   left join wf_dictionary_data wf on  wf.type='1' and wf.`code`= p.process_less_code  order by p.create_date desc");
		sqlPageQuery.setQuerySql(sql.toString());
		PageResult<Object[]> page = findDataWithPage(sqlPageQuery);
		return page;
	}
	
	
	public ProcessAuth insertProcessAuth(ProcessAuth entity){
		return insert(entity);
	}
	
	
	public List<Object[]> findObjectsList(String sql, Object... params) {
		return super.findObjectsList(sql, params);
	}
	
	
	public ProcessAuth findProcessAuthById(String id){
		return super.getById(ProcessAuth.class, id);
	}
	
	public int updateProcessAuthStatus(String id,String status){
		return super.execute("update process_auth set  auth_status = ? where id = ? ",status, id);
	}
	
	public  User findProcessAuthPerson(String psnCode,String processType){
		return  super.findEntity("  select t.employee_no no, t.employee_code code,t.employee_account account,t.employee_namecn cname,t.email email,t.mobile mobile ,t.telephone phone from o2o_employee t  where  t.employee_no in ( select roll_iner_code from process_auth where auth_bigin_date<=now()  and auth_end_date >= now() and auth_status ='Y'  and roll_outer_code = ? and process_less_code = ? )",User.class, psnCode,processType);
	}
}
